/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




package learn.round1B;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author robit
 */
public class FileFixIt{

    FileFixIt(){}
    private static Scanner s = null;
    private static PrintWriter o = null;
    private static int reckon(){
       return reckon1_2();
    }
    /**
    * calculate the answer
    */
    private static int reckon1_0() {
        int N=Int();
        int M=Int();
        ArrayList [] existDir = new ArrayList[N];
        ArrayList [] newDir = new ArrayList[M];
        for(int i=0;i<N;i++){
           existDir[i] = new ArrayList(Arrays.asList(String().split("/")));
           existDir[i].remove(0);
        }
        for(int i=0;i<M;i++){
           newDir[i]=new ArrayList(Arrays.asList(String().split("/")));
           newDir[i].remove(0);
        }
        Tree.counter=0;
        Tree.counting=false;
        Tree oldt = new Tree("ROOT");
        //Tree newt = new Tree("Root");
        for(int i=0;i<N;i++){
           oldt.addClone(existDir[i]);
        }
        Tree.counting=true;
        for(int i=0;i<M;i++){
           oldt.addClone(newDir[i]);
        }
        return Tree.counter;
    }

    static class Tree{
        static boolean counting;
        static int counter;

        ArrayList childname = new ArrayList();
        ArrayList<Tree> childnode = new ArrayList<Tree>();
        final String label;
        public Tree(String label) {
            this.label=label;
        }
        void addClone(ArrayList path){
            add((ArrayList)path.clone());
        }
        void add(ArrayList path){
           if(path.isEmpty())return;
           int idx = childname.indexOf(path.get(0));
           if(idx>-1){
               path.remove(0);
               childnode.get(idx).add(path);
               return;
           }
           childname.add(path.get(0));
           Tree newNode = new Tree((String)path.get(0));
           childnode.add(newNode);
           if(counting)counter++;
           path.remove(0);
           newNode.add(path);
        }

        void print(String pre){
            System.out.println(pre+"*"+label);
            for(Tree t:childnode){
                t.print(pre+"*"+label);
            }
        }
        void print(){
            print("");
        }
    }

    private static int reckon1_1(){
        int N=Int();
        int M=Int();
        //System.out.println("1.1");
        HashSet ext=new HashSet();
        String[] crt=new String[M];
        for(int i=0;i<N;i++){
            ext.add(String());
        }
        for(int i=0;i<M;i++){
            crt[i]=String();
        }
        int count=0;
        for(int i=0;i<M;i++){
            Pattern p=Pattern.compile("/\\w+");
            Matcher m=p.matcher(crt[i]);
            StringBuilder subpath=new StringBuilder();
            while(m.find()){
                //println(subpath.toString());
                subpath.append(m.group());
                if(!ext.contains(subpath.toString())){
                    ext.add(subpath.toString());
                    count++;
                }
            }
        }
        return count;
    }

    private static int reckon1_2(){
        int N=Int();
        int M=Int();
        String[][] oldPath=new String[N][];
        String[][] newPath=new String[M][];
        for(int i=0;i<N;i++)oldPath[i]=String().split("/");
        for(int i=0;i<M;i++)newPath[i]=String().split("/");
        Node root=new Node();
        for(int i=0;i<N;i++){
            insert(root,oldPath[i],1);
        }
        count=0;
        for(int i=0;i<M;i++){
            insert(root,newPath[i],1);
        }
        return count;
    }
    static int count=0;
    static class Node{
        HashMap<String,Node> child=new HashMap<String, Node>();
    }
    static void insert (Node parent, String[] paths, int idx){
        if(idx>=paths.length)return;
        Node child=parent.child.get(paths[idx]);
        if(child==null){
            //mkdir
            count++;
            child=new Node();
            parent.child.put(paths[idx], child);
        }
        insert(child,paths,idx+1);
    }
    private static void print(String str){
        System.out.print(str);
    }
    private static void println(String str){
        System.out.println(str);
    }
    private static int min(int a,int b){
        return Math.min(a,b);
    }
    private static int max(int a,int b){
        return Math.max(a,b);
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here

        try {
            //String filename="test";
            String prob="A";
            //String filename=prob+"-small-practice";
            String filename=prob+"-large-practice";

            s = new Scanner(
                    new BufferedReader(new FileReader(filename+".in")));
            //s.useLocale(Locale.US);
            o = new PrintWriter(
                    new BufferedWriter(new FileWriter(filename+".out")));

            // Determine input line number
            int lineNums = s.nextInt();

            for (int i = 1; i <= lineNums; i++) {
                o.println("Case #" + i + ": " + reckon());
            }
        } finally {
            s.close();
            o.close();
        }
    }


    private static int Int(){
        return s.nextInt();
    }
    private static long Long(){
        return s.nextLong();
    }
    private static String String(){
        return s.next();
    }

}
